package com.dz.risk.controller;

import com.dz.risk.common.ResponseVO;
import com.dz.risk.pojo.model.PageModel;
import com.dz.risk.service.ReportCalculatedVersionManagementService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * 报表计算版本管理
 *
 * @author Doke
 * @date 2021/9/9 14:12
 */
@RestController
@Api(tags = "报表计算版本管理Api")
@RequestMapping("/dz-ftsp/stest/reportCalculatedVersionManagement")
public class ReportCalculatedVersionManagementController {

    private final ReportCalculatedVersionManagementService reportCalculatedVersionManagementService;

    @Autowired
    public ReportCalculatedVersionManagementController(ReportCalculatedVersionManagementService reportCalculatedVersionManagementService) {
        this.reportCalculatedVersionManagementService = reportCalculatedVersionManagementService;
    }

    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页(默认 : 1)", dataType = "Integer"),
            @ApiImplicitParam(name = "rows", value = "显示条数(默认 : 10)", dataType = "Integer"),
            @ApiImplicitParam(name = "calculatedVersion", value = "计算日期 : yyyy-MM-dd", dataType = "Date"),
            @ApiImplicitParam(name = "reportFormsName", value = "报表名称", dataType = "String"),
            @ApiImplicitParam(name = "reportFormsSerialNumber", value = "报表编号", dataType = "String"),
    })
    @ApiOperation("分页查询报表计算版本信息")
    @GetMapping("/pageList")
    public ResponseVO pageList(PageModel pageModel, String reportFormsSerialNumber, String reportFormsName, @DateTimeFormat(pattern = "yyyy-MM-dd") Date calculatedVersion) {
        return ResponseVO.ok(reportCalculatedVersionManagementService.pageList(pageModel, reportFormsSerialNumber, reportFormsName, calculatedVersion));
    }

    @ApiImplicitParams({
            @ApiImplicitParam(name = "calculatingTime", value = "计算时间 : yyyy-MM-dd HH:mm:ss", required = true, dataType = "Date"),
            @ApiImplicitParam(name = "reportFormsId", value = "报表ID", required = true, dataType = "String"),
    })
    @ApiOperation("删除报表计算版本数据")
    @GetMapping("/deleteByReportFormsIdAndCalculatingTime")
    public ResponseVO deleteByReportFormsIdAndCalculatingTime(@RequestParam("reportFormsId") String reportFormsId, @RequestParam("calculatingTime") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date calculatingTime) {
        reportCalculatedVersionManagementService.deleteByReportFormsIdAndCalculatingTime(reportFormsId, calculatingTime);
        return ResponseVO.ok();
    }

}
